﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CowsAndBulls
{
    class ScoreBoard : IComparable
    {
        private int countAttempts;
        private String playerName;

        public ScoreBoard(int attempts, String name)
        {
            this.CountAttempts = attempts;
            this.playerName = name;
        }

        public int CountAttempts
        {
            get
            {
                return countAttempts;
            }
            set
            {
                countAttempts = value;
            }
        }

        public String PlayerName
        {
            get
            {
                return playerName;
            }
            set
            {
                playerName = value;
            }
        }

        public int CompareTo(Object obj)
        {
            ScoreBoard board = (ScoreBoard)obj;
            if (this.CountAttempts > board.CountAttempts)
                return 1;
            else
                if (this.CountAttempts < board.CountAttempts)
                    return -1;
                else
                {
                    if (this.playerName.CompareTo(board.playerName) == 1)
                    {
                        return 0;
                    }
                    else
                        if (this.playerName.CompareTo(board.playerName) == -1)
                        {
                            return -1;
                        }
                        else return 0;
                }
        }

        override public String ToString()
        {
            return String.Format("{0,-12} ---> {1} attempts", playerName, CountAttempts);
        }

        public void InsertPlayerInScoreBoard(List<ScoreBoard> list)
        {
            list.Add(this);
            list.Sort();
            if (list.Count > 5)
            {
                list.RemoveAt(list.Count - 1);
            }
        }
    }
}
